package com.atguigu.gmall.mq.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.service.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author: 封捷
 * @create-date: 2022/9/9 10:59
 */
@RestController
public class MQController {

    @Autowired
    private RabbitService rabbitService;

    @RequestMapping("/mq/sendConfirm")
    public Result<Void> sendMessageConfirm() {

        // 1、确定要发送消息的内容
        String message =
                "hello brother gui" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

        // 2、指定交换机
        String exchange = "exchange.brother_gui";

        // 3、指定路由键
        String routingKey = "routingKey.brother_gui";

        // 4、发送消息
        boolean sendResult = rabbitService.sendMessage(exchange, routingKey, message);

        return sendResult?Result.ok():Result.<Void>fail().message("消息发送失败！");
    }

}
